/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.contorller.trans;

import com.apache.api.vo.ResultEntity;
import com.apache.api.vo.ResultMsg;
import com.apache.cache.util.Validator;
import com.apache.client.InfoReleaseCoreCleint;
import com.apache.database.model.Page;
import com.apache.portal.common.PortalPlugin;
import com.apache.portal.common.annotion.BeanFactory;
import com.apache.portal.common.connector.impl.AdapterFactory;
import com.apache.portal.common.oscache.BaseOsCache;
import com.apache.portal.common.oscache.OsCacheOtherManager;
import com.apache.portal.common.restfull.RequestMapping;
import com.apache.portal.common.restfull.ResultFullAnntation;
import com.apache.portal.common.restfull.SupperAction;
import com.apache.portal.common.util.FileOperate;
import com.apache.portal.common.util.PortalPubFactory;
import com.apache.tools.StrUtil;
import com.apache.uct.common.LoginUser;
import com.apache.uct.common.ToolsUtil;
import com.apache.uct.common.entity.Dept;
import com.apache.uct.common.entity.Org;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.*;

/**
 * description:  列表信息获取公共接口实现Action
 *
 * @author dyhou 创建时间：2016-7-7
 */
@SuppressWarnings("serial")
@ResultFullAnntation(name = "transListAction", urlPatterns = "/trans/list/*")
public class TransListAction extends SupperAction {

    private PortalPlugin netPlugin;

    private PortalPlugin fusPlugin;

    private PortalPlugin orgPlugin;

    private PortalPlugin uctPlugin;

    private PortalPlugin memberPlugin;

    private PortalPlugin auditPlugin;

    private PortalPlugin dictPlugin;

    private PortalPlugin wcmPlugin;

    private BaseOsCache oscache;

    public void init() {
        netPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("net");
        fusPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("fus");
        orgPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("org");
        uctPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("uct");
        memberPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("member");
        auditPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("audit");
        dictPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("dict");
        wcmPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("wcm");
        oscache = OsCacheOtherManager.getInstance().getBaseOsCache("trans_infos_", 60);//
    }

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     */
    public void doInvoke(HttpServletRequest request, HttpServletResponse response,
            String methodType) throws Exception {
        String doCode = StrUtil.doNull(request.getParameter("doCode"), "dymicSql");
        Method method = doInvoke(this.getClass(), request, response, methodType, doCode);
        if (null != method) {
            Object obj = method.invoke(this, request, response);
            if (!ToolsUtil.isEmpty(obj)) {
                JSONObject array = JSONObject.fromObject(obj);
                this.outputJson(array.toString(), response, request.getParameter("callback"));
            }
        } else {
            gotoErrorPage(request, response, "请求方式有误或请求地址未定义");
        }
    }

    /**
     * 查询标的列表
     */
    @RequestMapping(value = "dymicSql", method = "get")
    protected Object dymicSql(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "dymicSql");
        String modelTypes = params.get("modelTypes");
        //如果不传modelTypes，还是沿用以前自己写sql的方式，否则走ius的公共方法。
        params.put("resultType", StrUtil.doNull(request.getParameter("resultType"), "objInfo"));
        params.put("resultObjType", "list");
        params = AdapterFactory.getInstance()
                .getReqParamForBefor("setReqParam", params, request, response);//前拦截
        String execptionMsg = String.valueOf(params.get("execptionMsg"));
        if (StrUtil.isNotNull(execptionMsg)) {
            ResultMsg msg = new ResultMsg("F", execptionMsg);
            return msg;
        }
        //        String cacheKey = oscache.getCacheKey("dymicSql", params);
        // ResultEntity entity = (ResultEntity) oscache.get(cacheKey);
        // if (ToolsUtil.isEmpty(entity)) {
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //}
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            //            if (null != entity.getEntity()) {
            //                oscache.put(cacheKey, entity);
            //            }
            if ("RelationByProId".equals(request.getParameter("sqlKeyId"))) {
                resultMap.put("dealFlag", "T");//需特殊处理
            }
            getListData(entity, resultMap);
        }
        return resultMap;
    }

    @RequestMapping(value = "fileList", method = "get")
    protected Object fileList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        String root = Validator.getDefaultStr(request.getParameter("fileRoot"),
                ToolsUtil.getInstance().getLocalByKey("config.properties", "temp_path"));
        String floderName = FileOperate.getInstance()
                .formatFilePath(request.getParameter("floderName"));
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String filePath = FileOperate.getInstance().formatFilePath(root);
        String parentId = "0";
        if (ToolsUtil.isNotNull(floderName)) {
            filePath += floderName.replace("-", "/");
            parentId = floderName.replace("/", "-");
        }
        log.info("读取指定目录下文件；"+filePath);
        File[] files = FileOperate.getInstance().getFileList(filePath);
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        if (null != files && files.length > 0) {
            //			if (!ToolsUtil.isNull(floderName)) {
            //				Map<String, String> upFloder = new HashMap<String, String>();
            //				upFloder.put("id", floderName);
            //				upFloder.put("isfloder", "T");
            //				upFloder.put("parentId", parentId);
            //				upFloder.put("text", floderName.substring(floderName.lastIndexOf("/") + 1));
            //				list.add(upFloder);
            //			}
            String filters = ToolsUtil.getInstance()
                    .getLocalByKey("config.properties", "filter_temp");
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isDirectory()) {
                    if (filters.indexOf(file.getName()) != -1) {
                        log.info("过滤目录；"+file.getName());
                        continue;
                    }
                }else{
                    String fileName = file.getName();
                    String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
                    if(filters.indexOf(suffix.toLowerCase())>-1){
                        log.info("过滤文件；"+fileName);
                        continue;
                    }
                }
                Map<String, String> map = new HashMap<String, String>();
                String path = FileOperate.getInstance().formatFilePath(file.getPath());
                map.put("floder", floderName.replace("-", "/"));
                map.put("id", path.replace(FileOperate.getInstance().formatFilePath(root), "")
                        .replace("/", "-"));
                map.put("isfloder", file.isDirectory() ? "T" : "F");
                map.put("parentId", parentId);
                map.put("text", file.getName());
                list.add(map);
            }
            resultMap.put("total", list.size());
            resultMap.put("rows", list);
        }
        return resultMap;
    }

    /**
     * 查询标的列表
     */
    @RequestMapping(value = "proList", method = "get")
    protected Object proList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, resultMap);
        }
        return resultMap;
    }

    /**
     * 查询标的列表(带PUB信息)
     */
    @RequestMapping(value = "proListAll", method = "get")
    protected Object proListAll(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        BaseOsCache oscache = OsCacheOtherManager.getInstance().getBaseOsCache("net_infos_", 10);
        String cacheKey = oscache.getCacheKey("proListAll_", params);
        Object obj = oscache.get(cacheKey);
        if (!ToolsUtil.isEmpty(obj)) {
            return obj;
        }
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, resultMap);
            oscache.put(cacheKey, resultMap);
        }
        return resultMap;
    }

    /**
     * 钱包，F001：开户检测
     */
    @RequestMapping(value = "F001", method = "get")
    protected Object F001(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) fusPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("fus")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("flag", "F");
        resultMap.put("msg", "钱包检测通信失败");

        String fundsOpen = "F";
        if ("true".equals(entity.getResult())) {
            if (null == entity.getEntity()) {
                resultMap.put("flag", "F1");//不存在钱包账户，需要开通
                resultMap.put("msg", entity.getMessage());
            } else {
                resultMap.put("flag", "T");//已经存在，直接使用
                resultMap.put("msg", "已开通钱包");
                fundsOpen = "T";
            }
        }
        //开通钱包标记记录到session里面去
        request.getSession().setAttribute("fundsOpen", fundsOpen);
        return resultMap;
    }

    /**
     * 钱包，F003：账户查询（根据资金账号）
     */
    @RequestMapping(value = "F003", method = "get")
    protected Object F003(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) fusPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("fus")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("flag", "F");
        resultMap.put("msg", "通信失败");

        String fundsOpen = "F";//F000
        if ("true".equals(entity.getResult())) {
            String rent = String.valueOf(entity.getEntity());
            if (StrUtil.isNotNull(rent) && !"false".equals(rent)) {
                resultMap.put("flag", "T");//已开通
                resultMap.put("msg", entity.getMessage());
                resultMap.put("msg", rent);
            } else {
                resultMap.put("flag", "F1");//已经存在，直接使用
                resultMap.put("msg", "此用户未开通钱包");
                fundsOpen = "T";
            }
        }
        return resultMap;
    }

    /**
     * 钱包，F004：资金余额
     */
    @RequestMapping(value = "F004", method = "get")
    protected Object F004(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) fusPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("fus")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("flag", "F");
        resultMap.put("msg", "钱包余额查询失败");

        if ("true".equals(entity.getResult())) {
            if (null == entity.getEntity() || "false".equals(entity.getEntity().toString())) {
                resultMap.put("msg", entity.getMessage());
            } else {
                resultMap.put("flag", "T");//已经存在，直接使用
                resultMap.put("msg", entity.getEntity());
            }
        }
        return resultMap;
    }

    /**
     * 钱包，F006：资金明细查询
     */
    @RequestMapping(value = "F006", method = "get")
    protected Object F006(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) fusPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("fus")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();

        if (null == entity.getEntity() || "false".equals(entity.getEntity().toString())) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, resultMap);
        }
        return resultMap;
    }

    /**
     * 钱包，F009:账户列表查询
     */
    @RequestMapping(value = "F009", method = "get")
    protected Object F009(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) fusPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("fus")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();

        if (null == entity.getEntity() || "false".equals(entity.getEntity().toString())) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, resultMap);
        }
        return resultMap;
    }

    /**
     * 查询成交信息列表
     */
    @RequestMapping(value = "dealList", method = "get")
    protected Object dealList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        log.info(params);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info(entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询会员列表
     */
    @RequestMapping(value = "memberList", method = "get")
    protected Object memberList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) memberPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("member")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询用户信息列表
     */
    @RequestMapping(value = "userList", method = "get")
    public Object userList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        log.info(params);
        LoginUser loginUser = PortalPubFactory.getInstance().getLoginUser(request);
        if (!"1".equalsIgnoreCase(loginUser.getSysFlag())) {
            if ("0".equalsIgnoreCase(loginUser.getSysFlag())) {
                String deptId = StrUtil.doNull(loginUser.getDeptId(), "");
                params.put("dataDeptIds", StrUtil.doNull(loginUser.getDataDeptIds(), deptId));
            }
            String orgId = StrUtil.doNull(loginUser.getOrgId(), "");
            params.put("dataOrgIds", StrUtil.doNull(loginUser.getDataOrgIds(), orgId));
        }

        ResultEntity entity = (ResultEntity) uctPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info(entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询用户信息列表
     */
    @RequestMapping(value = "isExist", method = "post")
    public Object isExist(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        ResultEntity entity = (ResultEntity) uctPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        Map<String, Boolean> map = new HashMap<String, Boolean>();

        if (entity != null && null == entity.getEntity()) {
            map.put("valid", true);
        } else {
            map.put("valid", false);
        }
        return map;
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "orgList", method = "get")
    protected Object orgList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "orgList");
        params.put("pageIndex", StrUtil.doNull(params.get("page"), params.get("pageIndex")));
        params.put("pageSize", StrUtil.doNull(params.get("rows"), params.get("pageSize")));
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "orgActData", method = "get")
    protected Object orgActData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "orgActData");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            JSONArray jary = JSONArray.fromObject(entity.getEntity());
            this.outputJson(jary.toString(), response, request.getParameter("callback"));
            return null;
        }
        return data;
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "orgInit", method = "get")
    protected void orgInit(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "orgList");
        //	params.put("orgAll", "orgAll");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            List<Org> orgList = (List) entity.getEntity();
            net.sf.json.JSONObject jvo = new net.sf.json.JSONObject();
            net.sf.json.JSONArray jary = new net.sf.json.JSONArray();
            if (ToolsUtil.isEmpty(orgList))
                this.outputJson(jary.toString(), response, request.getParameter("callback"));
            for (int i = 0; i < orgList.size(); i++) {
                Org ovo = orgList.get(i);
                jvo.put("orgId", ovo.getOrgId());
                jvo.put("orgCname", ovo.getOrgCname());
                jvo.put("orgEname", ovo.getOrgEname());
                jary.add(jvo);
            }
            this.outputJson(jary.toString(), response, request.getParameter("callback"));
        }
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "deptList", method = "get")
    protected Object deptList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "deptList");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "deptInit", method = "get")
    protected void deptInit(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "deptList");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            List<Dept> list = (List) entity.getEntity();
            net.sf.json.JSONArray jary = new net.sf.json.JSONArray();
            if (ToolsUtil.isEmpty(list)) {
                this.outputJson(jary.toString(), response, request.getParameter("callback"));
            }
            for (int i = 0; i < list.size(); i++) {
                Dept dvo = list.get(i);
                net.sf.json.JSONObject jvo = new net.sf.json.JSONObject();
                jvo.put("deptId", dvo.getDeptId());
                jvo.put("deptCname", dvo.getDeptCname());
                jary.add(jvo);
            }
            this.outputJson(jary.toString(), response, request.getParameter("callback"));
        }
    }

    /**
     * 查询角色列表
     */
    @RequestMapping(value = "roleList", method = "get")
    protected Object roleList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "roleList");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询系统列表
     */
    @RequestMapping(value = "listSys", method = "get")
    protected Object listSys(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "listSys");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询资源列表
     */
    @RequestMapping(value = "actList", method = "get")
    protected Object actList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "actList");
        ResultEntity entity = (ResultEntity) orgPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("org")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询日志模型列表
     */
    @RequestMapping(value = "logModelList", method = "get")
    protected Object logModelList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) uctPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("uct")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询审记日志列表
     */
    @RequestMapping(value = "logOperationList", method = "post")
    protected Object logOperationList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) uctPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询数据字典dictCate列表
     */
    @RequestMapping(value = "dictCateList", method = "get")
    protected Object dictCateList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        String sysName = request.getParameter("sysName");
        sysName = Validator.getDefaultStr(sysName, "default");
        params.put("datasource", sysName);

        ResultEntity entity = (ResultEntity) dictPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("dict")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询数据字典dictCate列表
     */
    @RequestMapping(value = "dictItemList", method = "get")
    protected Object dictItemList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) dictPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("dict")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询我的报名列表
     */
    @RequestMapping(value = "applyList", method = "get")
    protected Object applyList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        Map<String, Object> data = new HashMap<String, Object>();
        LoginUser loginUser = PortalPubFactory.getInstance().getLoginUser(request);
        if (ToolsUtil.isEmpty(loginUser)) {
            data.put("flag", "F");
            data.put("msg", "未登录，请重新登录！");
            return data;
        }
        //暂时以用户类型来判断 ,当userType=manager时，代表业务人员。
        if ("manager".equals(loginUser.getUserType())) {
            //业务人员通过项目ID查询该项目的报名人员列表，无需传applyUserEname。
        } else {
            params.put("applyUserEname", loginUser.getUserEname());//查询我的报名项目
        }

        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);//  PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询转让方列表
     */
    @RequestMapping(value = "sellerList", method = "get")
    protected Object sellerList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询结算业务列表
     */
    @RequestMapping(value = "settleFlowList", method = "get")
    protected Object settleFlowList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询结算凭单列表
     */
    @RequestMapping(value = "settleBillList", method = "get")
    protected Object settleBillList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        Map<String, Object> data = new HashMap<String, Object>();
        LoginUser loginUser = PortalPubFactory.getInstance().getLoginUser(request);
        if (ToolsUtil.isEmpty(loginUser)) {
            data.put("flag", "F");
            data.put("msg", "未登录，请重新登录！");
            return data;
        }
        //暂时以用户类型来判断 ,当userType=manager时，代表业务人员。
        if ("manager".equals(loginUser.getUserType())) {
            //业务人员通过项目ID查询凭单列表，无需传userEname。
        } else {
            params.put("userEname", loginUser.getUserEname());//查询我的报名项目
        }
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    @RequestMapping(value = "auditList", method = "get")
    protected Object auditList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) auditPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("audit")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    private void getListData(ResultEntity entity, Map<String, Object> data) {
        data.put("flag", "T");
        if (entity.getEntity() instanceof Page) {
            Page page = (Page) entity.getEntity();
            data.put("total", page.getCount());
            data.put("rows", page.getPageObjects());
        } else if (entity.getEntity() instanceof List) {
            List list = (List) entity.getEntity();
            data.put("total", list.size());
            data.put("rows", list);

            /*if ("T".equals(data.get("dealFlag"))) {
                if (list.size() > 0) {
                    for (Object object : list) {
                        ProVo proVo = (ProVo) object;
                        Member buyer = proVo.getBuyer();
                        data.put("pro", proVo.getPro());
                        data.put("pub", proVo.getPub());
                        data.put("deal", proVo.getDealList());
                        data.put("flow", proVo.getFlowList());
                        data.put("bill", proVo.getBillList());
                        data.put("seller", proVo.getSeller());
                        data.put("buyer", proVo.getBuyer());
                    }
                }
            }*/
        } else {
            if (null != entity.getEntity()) {
                List list = new ArrayList(1);
                list.add(entity.getEntity());
                data.put("total", "1");
                data.put("rows", list);
                data.put("msg", entity.getMessage());
            } else {
                data.put("flag", "F");
                data.put("msg", entity.getMessage());
            }
        }
    }

    ///以下稿件栏目相关////////////////////

    /**
     * 查询栏目列表
     */
    @RequestMapping(value = "cllist", method = "get")
    protected Object cllist(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) wcmPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("wcm")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 查询稿件列表
     */
    @RequestMapping(value = "mtlist", method = "get")
    protected Object mtlist(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) wcmPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("wcm")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    ///稿件栏目相关操作结束////////////////////

    /**
     * 查看凭证信息列表
     */
    @RequestMapping(value = "transBillList", method = "get")
    protected Object transBillList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        } else {
            getListData(entity, data);
        }
        return data;
    }

    /**
     * 获取竞价结果
     */
    @RequestMapping(value = "pushBid", method = "get")
    protected Object pushBidInfo(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        LoginUser loginUser = PortalPubFactory.getInstance().getLoginUser(request);
        if (ToolsUtil.isEmpty(loginUser)) {
            gotoLogin(request, response, "");
            return null;
        }
        Map<String, String> params = this.getParameterMap(request);
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
        }
        return entity;
    }

    /**
     * 查询机构列表
     */
    @RequestMapping(value = "treeAct", method = "get")
    protected Object actsData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "treeAct");
        Object obj = uctPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null == obj) {
            log.info("获取失败：数据查询失败");
        } else {
            JSONArray jary = JSONArray.fromObject(obj);
            this.outputJson(jary.toString(), response, request.getParameter("callback"));
            return null;
        }
        return data;
    }

    /**
     * 旧版查询动态表单列表 infoList
     * add 2016-12-10 xhe 专门给贝桥用的
     */
    @RequestMapping(value = "infoList", method = "get")
    protected Object infoList(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);

        if (StrUtil.isNotNull(String.valueOf(params.get("infoTitle")))) {
            params.put("infoTitle", "like '%" + String.valueOf(params.get("infoTitle")) + "%'");
        }
        if (StrUtil.isNotNull(String.valueOf(params.get("isTop")))) {
            params.put("orderby", "is_top_time desc");//按照推荐查询，就以推荐时间倒序
        } else {
            params.put("orderby", "create_time desc");
        }
        params.put("pageSize", StrUtil.doNull(String.valueOf(params.get("pageSize")), "10"));
        params.put("pageIndex", StrUtil.doNull(String.valueOf(params.get("pageIndex")), "1"));
        Object resutlData = InfoReleaseCoreCleint.getInstance().selectInfo(params);
        Map<String, Object> data = new HashMap<String, Object>();
        if (null != resutlData) {
            data.put("flag", "T");
            if (resutlData instanceof Page) {
                Page page = (Page) resutlData;
                data.put("total", page.getCount());
                data.put("rows", page.getPageObjects());
            } else {
                List list = (List) resutlData;
                data.put("total", list.size());
                data.put("rows", list);
            }
        }
        return data;
    }


    /**
     * list转换树Tree格式的json
     * @date 2018/06/25
     */
    @RequestMapping(value = "getTreeData", method = "get")
    protected Object getTreeData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "dymicSql");
        String modelTypes = params.get("modelTypes");

        String objName = params.get("objName");
        String isFile = params.get("isFile");
        if(StrUtil.isNull(objName)){
            ResultMsg msg = new ResultMsg("F", "objName参数不能为空");
            return msg;
        }

        //如果不传modelTypes，还是沿用以前自己写sql的方式，否则走ius的公共方法。
        params.put("resultType", StrUtil.doNull(request.getParameter("resultType"), "objInfo"));
        params.put("resultObjType", "list");
        params = AdapterFactory.getInstance()
                .getReqParamForBefor("setReqParam", params, request, response);//前拦截
        String execptionMsg = String.valueOf(params.get("execptionMsg"));
        if (StrUtil.isNotNull(execptionMsg)) {
            ResultMsg msg = new ResultMsg("F", execptionMsg);
            return msg;
        }
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("flag", "F");
        resultMap.put("msg", "查询失败");
        if (null == entity.getEntity()) {
            log.info("获取失败：" + entity.getMessage());
            resultMap.put("msg", "查询失败");
        } else {
            if (!(entity.getEntity() instanceof List)) {
                resultMap.put("msg", "查询成功，但返回数据必须是list");
                log.info("查询结果必须是list：" + entity.getMessage());
            }

            //把list转换树形结构的json生成js文件并且返回
            List<Map> list = (List<Map>) entity.getEntity();
            if(list!=null && list.size()>0){
                Map objMap = (Map)list.get(0).get(objName);
                String fatherId = String.valueOf(objMap.get("fatherId"));
                String treeLevel = String.valueOf(objMap.get("treeLevel"));
                String nodeNo = String.valueOf(objMap.get("nodeNo"));
                String nodeId = String.valueOf(objMap.get("nodeId"));
                String nodeName = String.valueOf(objMap.get("nodeName"));
               if(StrUtil.isNull(fatherId) || StrUtil.isNull(treeLevel) || StrUtil.isNull(nodeNo) || StrUtil.isNull(nodeId) || StrUtil.isNull(nodeName) ){
                   ResultMsg msg = new ResultMsg("F", "对象["+objName+"]必须包含[fatherId,treeLevel,nodeNo,nodeId,nodeName]这些属性，且值不能为空！否则不能解析Tree树形结构！");
                   return msg;
               }

                //用于无限极自定义解析
                JSONArray jsonTreeArray = listToTreeDataJson(list,objName,"0");
                String treeJsonStr = JSONArray.fromObject(jsonTreeArray).toString();
                if(jsonTreeArray.size()>0){
                    log.info("转换树形的字符串格式1->"+treeJsonStr);
                    resultMap.put("flag", "T");
                    resultMap.put("msg", "查询成功，转换成功");
                    resultMap.put("rowsTree",jsonTreeArray);

                    if("T".equals(isFile)){
                        String fileName = "tree-data-" + objName.toLowerCase() + ".js";
                        log.info("开始生成json文件："+fileName);
                        String filePath = ToolsUtil.getClassLoaderPath().replaceAll("WEB-INF/classes/", "") + "js/dictData/"+ fileName;
                        boolean fileResult = FileOperate.getInstance().newCreateFile(filePath,treeJsonStr);
                        log.info("["+fileName+"]json文件生成结果："+fileResult);
                    }
                }


                //用于级联
                JSONArray jsonReleArray = listToTreeReleJson(list,objName,"0");
                if(jsonReleArray.size()>0){
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("citylist",jsonReleArray);
                    String releJsonStr = JSONObject.fromObject(jsonObject).toString();
                    log.info("转换树形的字符串格式2->"+releJsonStr);
                    resultMap.put("flag", "T");
                    resultMap.put("msg", "查询成功，转换成功");
                    resultMap.put("rowsRele",jsonReleArray);

                    if("T".equals(isFile)){
                        String fileName = "jquery.select-dict-data-" + objName.toLowerCase() + ".js";
                        log.info("开始生成json文件："+fileName);
                        String filePath = ToolsUtil.getClassLoaderPath().replaceAll("WEB-INF/classes/", "") + "js/dictData/"+ fileName;
                        boolean fileResult = FileOperate.getInstance().newCreateFile(filePath,releJsonStr);
                        log.info("["+fileName+"]json文件生成结果："+fileResult);
                    }
                }

            }
        }
        return resultMap;
    }

    /**
     * 生成格式，是参照省市区县那种三级联动的，用于那种下拉框的
     */
    private JSONArray listToTreeReleJson(List<Map> listData,String objName,String pid){
        JSONArray jsonArray = new JSONArray();
        //list生成JSON格式的树
        for(Map dms:listData){
            Map objMap = (Map)dms.get(objName);
            String fatherId = String.valueOf(objMap.get("fatherId"));
            String treeLevel = String.valueOf(objMap.get("treeLevel"));
            String nodeNo = String.valueOf(objMap.get("nodeNo"));
            String nodeId = String.valueOf(objMap.get("nodeId"));
            String nodeName = String.valueOf(objMap.get("nodeName"));
            if(fatherId.equals(pid)){
                if(treeLevel.equals("1")){
                    JSONObject jsonObj = new JSONObject();
                    jsonObj.put("p",nodeId+":"+nodeName);
                    JSONArray array = listToTreeReleJson(listData,objName,nodeId);
                    jsonObj.put("c",array);
                    jsonArray.add(jsonObj);
                }else if(treeLevel.equals("2")){
                    JSONObject jsonObj = new JSONObject();
                    jsonObj.put("n",nodeId+":"+nodeName);
                    JSONArray array = listToTreeReleJson(listData,objName,nodeId);
                    jsonObj.put("a",array);
                    jsonArray.add(jsonObj);
                }else if(treeLevel.equals("3")){
                    JSONObject jsonObj = new JSONObject();
                    jsonObj.put("s",nodeId+":"+nodeName);
                    jsonArray.add(jsonObj);
                }
            }
        }
        return jsonArray;
    }

    /**
     * 纯树形结构的
     */
    private JSONArray listToTreeDataJson(List<Map> listData,String objName,String pid){
        JSONArray jsonArray = new JSONArray();
        //list生成JSON格式的树
        for(Map dms:listData){
            Map objMap = (Map)dms.get(objName);
            String fatherId = String.valueOf(objMap.get("fatherId"));
            String treeLevel = String.valueOf(objMap.get("treeLevel"));
            String nodeNo = String.valueOf(objMap.get("nodeNo"));
            String nodeId = String.valueOf(objMap.get("nodeId"));
            String nodeName = String.valueOf(objMap.get("nodeName"));
            String nodeIcon = StrUtil.doNull(String.valueOf(objMap.get("nodeIcon")),"");
            if(fatherId.equals(pid)){
                JSONObject jsonObj = new JSONObject();
                jsonObj.put("fatherId",fatherId);
                jsonObj.put("treeLevel",treeLevel);
                jsonObj.put("dataId",nodeId);
                jsonObj.put("text",nodeName);
                jsonObj.put("nodeNo",nodeNo);
                jsonObj.put("nodeIcon",nodeIcon);
//                jsonObj.put("nodeName",nodeName);
                JSONArray array = listToTreeDataJson(listData,objName,nodeId);
                if(array.size()>0){
                    jsonObj.put("nodes",array);
                }
                jsonArray.add(jsonObj);
            }
        }
        return jsonArray;
    }

}
